package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppCommentReply;
import com.vf.admin.miaodong.entity.AppKnapsack;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Repository
public class AppKnapsackDao extends BaseDao<AppKnapsack> {

    /**
     * 查询用户id获取背包礼物
     * @param userid
     * @param splitPage
     * @return
     */
    public List<AppKnapsack> getABackpackGift(Integer userid, SplitPageBean splitPage) {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_knapsack where 1=1  ");
        sbStr.append(" and userid = ? ");
        paramList.add(userid);
        sbStr.append(" and status = 1 ");
        String sql = sbStr.toString();
        return this.queryList(sql,paramList, AppKnapsack.class,splitPage);
    }

    /**
     * 添加/修改
     */
    public void save(AppKnapsack haoYou) {
        if (haoYou.getId() != null && haoYou.getId() > 0) {
            this.update(haoYou);
        } else {
            haoYou.setId(this.add(haoYou));
        }
    }
    /**
     * 删除
     */
    public void del(Integer id) {
        if (id <= 0) {
            return;
        }
        String sql = "delete  from app_knapsack where id = ?";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(id);
        this.del(sql, paramList);
    }

    /**
     * 减少
     */
    public void jianshao(Integer id,Integer num) {
        if(StringEx.isNull(id)){
            return ;
        }
        String sql = " UPDATE app_knapsack SET liwushuliang = liwushuliang-?  WHERE id = ? ";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(num);
        paramList.add(id);
        this.update(sql,paramList);
    }

    /**
     * 更新用户头像
     * @param userid
     * @param pic 头像地址
     */
    public void updateImg(Integer userid,String pic){
        if(StringEx.isNull(userid)){
            return ;
        }
        if(StringEx.isNull(pic)){
            return;
        }
        String sql = " UPDATE app_knapsack SET userpic = ?  WHERE userid = ? ";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(pic);
        paramList.add(userid);
        this.update(sql,paramList);
    }
    /**
     * 更新用户昵称
     * @param userid
     * @param nick 昵称
     */
    public void updateNick(Integer userid,String nick){
        if(StringEx.isNull(userid)){
            return ;
        }
        if(StringEx.isNull(nick)){
            return;
        }
        String sql = " UPDATE app_knapsack SET usernick = ?  WHERE userid = ? ";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(nick);
        paramList.add(userid);
        this.update(sql,paramList);
    }

    /**
    * 获取我的背包
    * @Param: [userid]
    * @return: java.util.List<com.vf.admin.miaodong.entity.AppKnapsack>
    * @Author: zhouyunyi
    * @Date: 2021/07/29
    * @Time: 12:07
    */
    public List<AppKnapsack> getBeibao(Integer userid) {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_knapsack where 1=1  ");
        sbStr.append(" and userid = ? ");
        paramList.add(userid);
        sbStr.append(" and status = 1 ");
        sbStr.append(" and liwushuliang > 0 ");
        String sql = sbStr.toString();
        return this.queryList(sql,paramList, AppKnapsack.class);
    }

    /**
    * 获取背包详情
    * @Param: [userid]
    * @return: java.util.List<com.vf.admin.miaodong.entity.AppKnapsack>
    * @Author: zhouyunyi
    * @Date: 2021/07/29
    * @Time: 12:07
    */
    public AppKnapsack get(Integer id) {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_knapsack where 1=1  ");
        sbStr.append(" and id = ? ");
        paramList.add(id);
        sbStr.append(" and status = 1 ");
        String sql = sbStr.toString();
        return this.queryObj(sql,paramList, AppKnapsack.class);
    }
    /**
    * 根据用户id和礼物id获取背包详情
    * @Param: [userid]
    * @return: java.util.List<com.vf.admin.miaodong.entity.AppKnapsack>
    * @Author: zhouyunyi
    * @Date: 2021/07/29
    * @Time: 12:07
    */
    public AppKnapsack getUog(Integer userid,Integer giftid) {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_knapsack where 1=1  ");
        sbStr.append(" and userid = ? ");
        paramList.add(userid);
        sbStr.append(" and gifid = ? ");
        paramList.add(giftid);
        String sql = sbStr.toString();
        return this.queryObj(sql,paramList, AppKnapsack.class);
    }

}
